package com.hsy.leancloudchat.main

import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import cn.leancloud.im.v2.LCIMConversation
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.internal.ViewUtils.dpToPx
import com.hsy.leancloudchat.databinding.DialogConversationRequestBinding

class ConversationRequestBottomDialog(context: Context) : BottomSheetDialog(context) {
    private lateinit var mBinding: DialogConversationRequestBinding

    fun setAcceptListener(listener: (Int) -> Unit) {
        (mBinding.rvRequestConversation.adapter as ConversationRequestAdapter)
            .setAcceptListener(listener)
    }

    @SuppressLint("RestrictedApi")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = DialogConversationRequestBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        mBinding.root.layoutParams.height = dpToPx(context, 500).toInt() // 默认有最高限制

        mBinding.rvRequestConversation.apply {
            adapter = ConversationRequestAdapter(this@ConversationRequestBottomDialog)
            layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)
        }
    }

    fun setItemList(list: MutableList<LCIMConversation>) {
        (mBinding.rvRequestConversation.adapter as ConversationRequestAdapter)
            .conversationRequestList = list
    }
}